home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 16
/
CU Amiga Magazine's Super CD-ROM 16 (1997-10-16)(EMAP Images)(GB)[!][issue 1997-11].iso
/
CUCD
/
Utilities
/
Datatypes
/
acbm
/
classbase.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-30
|
8KB
|
304 lines
/*
**
** $VER: classbase.c 1.1 (30.5.97)
** acbm.datatype 1.1
**
** Library routines for a DataTypes class
**
** Written 1996/97 by Roland 'Gizzy' Mainz
** Original example source from David N. Junod
**
*/
/* main includes */
#include "classbase.h"
/****** acbm.datatype/--datasheed-- ******************************************
*
* NAME
* acbm.datatype -- data type for IFF ACBM pictures
*
* SUPERCLASS
* picture.datatype
*
* DESCRIPTION
* The acbm datatype, a sub-class of the picture.datatype, is
* used to load and save IFF ACBM pictures.
*
* This class is offloaded from the datatypes.library V45 example code
* and is the reference implementation of a picture.datatype subclass
* (using V42 API) which supports saving in it's local format (as used
* by converters like "DTConvert").
*
* METHODS
* OM_NEW -- Create a new picture object from a description file. The
* source may only be a file.
*
* OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
* method will be executed like OM_SET downstairs.
*
* OM_SET -- Pass msg to superclass and call GM_RENDER if retval from
* superclass was != 0UL.
*
* DTM_WRITE -- Save data in local (IFF ACBM) or superclass (IFF ILBM)
* format.
*
* All other methods are passed unchanged to superclass.
*
* ATTRIBUTES
* Following attributes are set by the object and are READ-ONLY for
* applications (if the datatype is used for saving (e.g. the
* application creates an empty acbm.datatype object and fills
* in some required atrributes as shown in the "DTConvert" example),
* these attributes are used by the encoder to create an IFF ACBM
* picture file):
*
* DTA_ObjName -- Set by an IFF NAME chunk. If missing,
* DTA_ObjName will take DTA_Name's value.
* DTA_ObjAuthor -- Set by an IFF AUTH chunk.
* DTA_ObjAnnotation -- Set by an IFF ANNO chunk.
* DTA_ObjCopyright -- Set by an IFF (C) chunk.
* DTA_ObjVersion -- Set by an IFF FVER chunk.
* DTA_NominalHoriz -- Same as PDTA_BitMapHeader -> bmh_Width
* DTA_NominalVert -- Same as PDTA_BitMapHeader -> bmh_Height
* PDTA_ModeID -- Set by an IFF ILBM/ACBM CAMG chunk. If missing
* or the value here is 0, BestModeIDA will
* select a value based on BMHD information.
* PDTA_NumColors -- Set by IFF ILBM/ACBM CMAP chunk
* PDTA_ColorRegisters -- Set by IFF ILBM/ACBM CMAP chunk
* PDTA_CRegs -- Set by IFF ILBM/ACBM CMAP chunk
* PDTA_BitMap -- The image itself, created from IFF ACBM ABIT
* chunk and some IFF ILBM/ACBM BMHD infos.
*
* BUGS
* - Images with more than 8 planes causes crashes (because AllocBitMap
* allocates only 8 plane pointers).
*
* TODO
* - Fixing the bugs above.
*
* - Add GRAB support (e.g. IFF ILBM GRAB chunk and matching PDTA_Grab
* chunk).
*
* HISTORY
* V1.1
* First public release.
*
* NOTES
*
* SEE ALSO
* picture.datatype
*
*******************************************************************************
*
*/
/****** acbm.datatype/--input_format-- ****************************************
*
* NAME
* IFF ACBM -- Amiga Contiguous BitMap
*
* DESCRIPTION
* FORM ACBM has the same format as FORM ILBM except the normal BODY
* chunk (Interleaved Bitmap) is replaced by an ABIT chunk (Amiga
* BITplanes).
*
* The ABIT chunk contains continous bitplane data. The chunk contains
* sequential data fro planes 0 through plane i.
*
* SEE ALSO
* - ARKM Devices: IFF part
*
* - iffparse.library autodocs
*
* - AmigaBasic LoadACBM/SaveACBM
*
* THANKS TO
* Carolyn Scheppner (CBM) for creating this format
*
*******************************************************************************
*
*/
/*****************************************************************************/
DISPATCHERFLAGS
struct IClass *ObtainACBMEngine( REGA6 struct ClassBase *cb )
{
return( (cb -> cb_Lib . cl_Class) );
}
/*****************************************************************************/
DISPATCHERFLAGS
struct Library *LibInit( REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
{
cb -> cb_SegList = seglist;
cb -> cb_SysBase = sysbase;
InitSemaphore( (&(cb -> cb_Lock)) );
if( (cb -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
{
/* Obtain ROM libs */
if( cb -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
{
if( cb -> cb_GfxBase = OpenLibrary( "graphics.library", 39UL ) )
{
if( cb -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
{
if( cb -> cb_IFFParseBase = OpenLibrary( "iffparse.library", 39UL ) )
{
if( cb -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
{
return( (&(cb -> cb_Lib . cl_Lib)) );
#ifdef COMMENTED_OUT
CloseLibrary( UtilityBase );
#endif /* COMMENTED_OUT */
}
CloseLibrary( IFFParseBase );
}
CloseLibrary( DOSBase );
}
CloseLibrary( GfxBase );
}
CloseLibrary( IntuitionBase );
}
}
return( NULL );
}
/*****************************************************************************/
DISPATCHERFLAGS
LONG LibOpen( REGA6 struct ClassBase *cb )
{
LONG retval = (LONG)cb;
BOOL success = TRUE;
ObtainSemaphore( (&(cb -> cb_Lock)) );
/* Use an internal use counter */
cb -> cb_Lib . cl_Lib . lib_OpenCnt++;
cb -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
if( (cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
{
if( (cb -> cb_Lib . cl_Class) == NULL )
{
success = FALSE;
if( cb -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
{
if( cb -> cb_SuperClassBase = OpenLibrary( "datatypes/picture.datatype", 39UL ) )
{
if( cb -> cb_Lib . cl_Class = initClass( cb ) )
{
success = TRUE;
}
}
}
}
}
if( !success )
{
CloseLibrary( (cb -> cb_SuperClassBase) );
CloseLibrary( (cb -> cb_DataTypesBase) );
cb -> cb_DataTypesBase = cb -> cb_SuperClassBase = NULL;
(cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
retval = 0L;
}
ReleaseSemaphore( (&(cb -> cb_Lock)) );
return( retval );
}
/*****************************************************************************/
DISPATCHERFLAGS
LONG LibClose( REGA6 struct ClassBase *cb )
{
LONG retval = 0L;
ObtainSemaphore( (&(cb -> cb_Lock)) );
if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
{
(cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
}
if( ((cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (cb -> cb_Lib . cl_Class) )
{
if( FreeClass( (cb -> cb_Lib . cl_Class) ) )
{
cb -> cb_Lib . cl_Class = NULL;
CloseLibrary( (cb -> cb_SuperClassBase) );
CloseLibrary( (cb -> cb_DataTypesBase) );
}
else
{
cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
}
}
ReleaseSemaphore( (&(cb -> cb_Lock)) );
if( cb -> cb_Lib . cl_Lib . lib_Flags & LIBF_DELEXP )
{
retval = LibExpunge( cb );
}
return( retval );
}
/*****************************************************************************/
DISPATCHERFLAGS
LONG LibExpunge( REGA6 struct ClassBase *cb )
{
BPTR seg;
if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
{
cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
seg = NULL;
}
else
{
Remove( (&(cb -> cb_Lib . cl_Lib . lib_Node)) );
seg = cb -> cb_SegList;
CloseLibrary( (cb -> cb_UtilityBase) );
CloseLibrary( (cb -> cb_IFFParseBase) );
CloseLibrary( (cb -> cb_DOSBase) );
CloseLibrary( (cb -> cb_GfxBase) );
CloseLibrary( (cb -> cb_IntuitionBase) );
FreeMem( (APTR)((ULONG)(cb) - (ULONG)(cb -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((cb -> cb_Lib . cl_Lib . lib_NegSize) + (cb -> cb_Lib . cl_Lib . lib_PosSize)) );
}
return( (LONG)seg );
}